<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
|==========================================================
| Code Igniter - by pMachine
|----------------------------------------------------------
| www.codeignitor.com
|----------------------------------------------------------
| Copyright (c) 2006, pMachine, Inc.
|----------------------------------------------------------
| This library is licensed under an open source agreement:
| www.codeignitor.com/docs/license.html
|----------------------------------------------------------
| File: helpers/ip_helper.php
|----------------------------------------------------------
| JAVASCRIPT HELPER
|==========================================================
*/

function jsInclude($jsFileArray)
{
  $includeStr="";
  if (!empty($jsFileArray))
  {
     $includeStr='<script type="text/javascript" src="'.BASEURL.JS_DIR;
     $includeStr .= implode("\" ></script>\n<script type=\"text/javascript\" src=\"".BASEURL.JS_DIR,$jsFileArray);
     $includeStr .= "\" ></script>\n";
  }
  return $includeStr;
}

//construit une chaine json à partir d'un tableau associatif
function buildJson($assocArr)
{
  $retStr="";
  foreach ($assocArr as $key=>$val)
  {
    switch(gettype($val))
    {
        case "boolean":
          $cleanval = $val ? "true" : "false" ;
          break;
        case "string":
          if (is_numeric($val)) {
            $cleanval = $val;
          } else {
            $cleanval="'".str_replace("\r","",str_replace("\n",'\n',addslashes($val)))."'";
          }
          break;
        default:
          $cleanval = "'$val'";
          break;  
    }
    $retStr .="'$key':$cleanval,";
  }
  return "{".substr($retStr,0,-1)."}";
}
  
  
//Construit une chaine xml à partir d'un tableau
function buildAjaxParams($paramsArray)
{
  $paramsStr="";
  foreach($paramsArray as $key => $value) {
    $paramsStr.="$key=\"$value\" ";
  }
  return $paramsStr;
}


?>
